import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = data => {
    const requiredFields = [];
    const reg = /^[A-Z]{2}$/;
    if(!data || !reg.test(data.shortCode))
        requiredFields.push(
            formatMessage({
                id: 'validator.shortCode',
                defaultMessage: '简码必须由俩位大写字母组成且'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    if(data && data.address && data.address.length > 300) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.required.address',
            defaultMessage: '联系地址长度已超过300字符，不能保存！'
        })}`);
        return false;
    }
    return true;
};
